<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${domainPackage}.${className}">

    <select id="selectById" resultType="${domainPackage}.${className}" parameterType="java.lang.String">
        select * from ${tableName} where id= ${id}
    </select>

    <select id="select" resultType="${domainPackage}.${className}" parameterType="java.util.Map">
        select * from ${tableName} where 1 = 1

        <if test="id!=null">
            and id=${id}
        </if>
        order by updateTime desc
    </select>

    <select id="selectCount" resultType="java.lang.Integer" parameterType="java.util.Map">
        select count(1) from ${tableName}
        where 1=1
        <if test="id !=null">
            and id=${id}
        </if>
    </select>

    <insert id="insert" parameterType="${domainPackage}.${className}">
        insert into ${tableName}
        (
            <#list fields as field>
            <#if field.colName != "updateTime" && !field.autoIncrement>
            `${field.colName}`,
            </#if>
            </#list>
            `updateTime`
         )
        values
        (
            <#list fields as field>
            <#if field.colName != "updateTime" && !field.autoIncrement>
            ${field.colNameForInsert},
            </#if>
            </#list>
            now()
        )
    </insert>

    <update id="updateById" parameterType="${domainPackage}.${className}">
        update ${tableName} set
        <#list fields as field>
        <#if field.colName != "updateTime" && field.colName != "id" && field.colName != "createBy">
        `${field.colName}` = ${field.colNameForInsert},
        </#if>
        </#list>
        `updateTime` = now()
        where `id` = ${id}
    </update>

    <delete id="deleteById" parameterType="java.lang.String">
        delete from ${tableName} where `id` = ${id}
    </delete>

</mapper>